<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); 
ini_set('display_errors', '1');
header("Content-type:text/html;charset=utf-8");

class Config extends a_base {

	public function __construct(){
		parent::__construct();
	}

	public function index()
	{
		$this->load->model('m_config');
		$where = "configid` != \"\" ";
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1')){
						unset($search[$key]);
						continue;
					}
					if($key == 'websitename'){
						$where .= " AND `t_config`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `t_config`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('config',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$data['info'] = $this->m_config->get_config($where);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/index',$data);
	}

	public function config_add($configid="")
	{
		if($configid){
			$data['info'] = $this->m_public->getRowInfo('config',array('configid'=>$configid));
		}else{
			$data['info'] = "";
		}
		$this->load->view('config/config_add',$data);
	}

	public function config_action($configid='')
	{
		$info = $this->input->post();
		if($configid){
			$this->m_public->editInfo(array('configid'=>$configid),$info,'config');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('config',$info);
			}
		}
		redirect('config/index');
	}

	public function admin()
	{
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('admin',array(),'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_public->getPageAllInfo('admin',array(),10,$start_page);
		if(!empty($data['list'])){
			foreach($data['list'] as $k=>$v){
				if($v['sysroleids']){
					$idArr = explode(',',$v['sysroleids']);
					foreach ($idArr as $key => $value) {
						# code...
						$nameArr = $this->m_public->getRowInfo('sysrole',array('sysroleid'=>$value),'rolename');
						$data['list'][$k]['rolename'][$key] = $nameArr['rolename'];
					}
				}else{
					continue;
				}
			}
		}
		//print_R($data['list']);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/admin',$data);
	}

	public function admin_add($adminid='')
	{
		if($adminid){
			$data['info'] = $this->m_public->getRowInfo('admin',array('adminid'=>$adminid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/admin_add',$data);
	}

	public function admin_setrole($adminid='')
	{
		if($adminid){
			$data['info'] = $this->m_public->getRowInfo('admin',array('adminid'=>$adminid),'adminname,sysroleids,adminid');
			if($data['info']['sysroleids']){
				$idArr = explode(',',$data['info']['sysroleids']);
				foreach ($idArr as $key => $value) {
					# code...
					if($value == -1){
						continue;
					}else{
						$data['info']['roleids'][] = $value;
						
					}
				}
			}
			$data['roleinfo'] = $this->m_public->getAllInfo('sysrole',array('isclose'=>0),'sysroleid,rolename');
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/admin_setrole',$data);
	}

	public function admin_setrole_action()
	{
		$data = $this->input->post();
		if($data['sysroleid']){
			$data['sysroleids'] = implode(',', $data['sysroleid']);
			unset($data['sysroleid']);
		}else{
			$data['sysroleids'] = '';
		}
		$this->m_public->editInfo(array('adminid'=>$data['adminid']),$data,'admin');
		//print_r($data);
		redirect("config/admin");
	}

	public function delete_info($url,$parmykey,$table,$ids)
	{
		if(!$ids){
			redirect("config/$url");
		}
		$idArr = explode('.', $ids);
		foreach($idArr as $k=>$v){
			$res = $this->m_public->delInfo($table,array($parmykey=>$v));
		}
		redirect("config/$url");
	}

	public function edit_close($url,$parmykey,$table,$val,$ids)
	{
		if(!$ids){
			redirect(b_url("config/$url"));
		}
		$idArr = explode('.', $ids);
		foreach($idArr as $k=>$v){
			$data['isclose'] = $val;
			$this->m_public->editInfo(array($parmykey=>$v),$data,$table);
		}
		redirect("config/$url");
	}

	public function admin_action($adminid='')
	{
		$info = $this->input->post();
		if($adminid){
            if($info['adminpass']){
                $info['adminpass'] = md5($info['adminpass']);
            }
			$this->m_public->editInfo(array('adminid'=>$adminid),$info,'admin');
		}else{
			if(!empty($info)){
				$info['manageadminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('admin',$info);
			}
		}
		redirect('config/admin');
	}

	public function adminlog()
	{

		$this->load->model('m_config');
		$where = "t_adminlog`.`adminlogid` != \"\" ";

		$search = $this->input->post();
		if(!empty($search)){
			foreach($search as $k=>$v){
				if($k == 'btnQuery'){
					continue;
				}
				if($v){
					switch ($k) {
						case 'logcontent':
							$where .= " AND `t_adminlog`.`$k` LIKE '%$v%' "; 
							break;
						case 'txtAdmin':
							$idArr = $this->m_public->getRowInfo('admin',array('adminname'=>$v),'adminid');
							$where .= " AND `t_adminlog`.`$k` = '".$idArr['adminid']."' "; 
							break;
						case 'txtAddTime1':
							$where .= " AND `t_adminlog`.`$k` >= '$v' "; 
							break;
						case 'txtAddTime2':
							$where .= " AND `t_adminlog`.`$k` <= '$v' "; 
							break;
						default:
							$where .= " AND `t_adminlog`.`$k` = '$v' "; 
							break;
					}
				}
			}
		}
		if(!$where){
			$where = array();
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_config->get_admin_log($where);
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => count($cntArr)//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_admin_log($where ,10,$start_page);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/admin_logs',$data);
	}

	public function admingroup(){
		$this->load->model('m_config');
		$where = "admingroupid` !=\"\" ";
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1')){
						unset($search[$key]);
						continue;
					}
					if($key == 'admingroupname'){
						//$this->db->like('title', 'match', 'both');
						$where .= " AND `$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('admingroup',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_admingroup($where,10,$start_page);
		//print_R($data['list']);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/admin_group',$data);
	}

	public function admingroup_add($admingroupid='')
	{
		if($admingroupid){
			$data['info'] = $this->m_public->getRowInfo('admingroup',array('admingroupid'=>$admingroupid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/admingroup_add',$data);
	}

	public function admingroup_action($admingroupid='')
	{
		$info = $this->input->post();
		if($admingroupid){
			$this->m_public->editInfo(array('admingroupid'=>$admingroupid),$info,'admingroup');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('admingroup',$info);
			}
		}
		redirect('config/admingroup');
	}

	public function admingroup_setadmin($admingroupid){
		$this->load->model('m_config');
		$where = "adminingroup`.`admingroupid` = '$admingroupid'";
		$data['groupinfo'] = $this->m_config->get_adminingroup($where);
		if(!empty($data['groupinfo'])){
			$a_where = "adminid` != \"\" ";
			foreach ($data['groupinfo'] as $key => $value) {
				$a_where .= " AND adminid != '".$value['adminid']."' ";
			}
		}else{
			$data['groupinfo'] = '';
		}
		$data['admingroupid'] = $admingroupid;
		$data['userinfo'] = $this->m_public->getAllInfo('admin',$a_where,'adminid,adminname');
		$this->load->view('config/admingroup_setadmin',$data);
	}

	public function admingroup_setadmin_action($admingroupid){
		$adminid = $this->input->post('adminid');
		$this->m_public->addRowInfo('adminingroup',array('adminid'=>$adminid,'admingroupid'=>$admingroupid));
		redirect("config/admingroup_setadmin/$admingroupid");
	}

	public function delete_adminingroup($admingroupid,$adminid){
		$this->m_public->delInfo('adminingroup',array('adminid'=>$adminid,'admingroupid'=>$admingroupid));
		redirect("config/admingroup_setadmin/$admingroupid");
	}

	//
	public function limit(){
		$this->load->model('m_config');
		$limitid = $this->input->get('parentid');
		if($limitid){
			$where = "parentid = '$limitid'";
			$data['limitid'] = $limitid;
		}else{
			$where = "parentid` = '0' ";
			$limitid = 0;
			$data['limitid'] = 0;
		}
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1')){
						unset($search[$key]);
						continue;
					}
					if($key == 'limitfield'){
						//$this->db->like('title', 'match', 'both');
						$where .= " AND `t_limit`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `t_limit`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('limit',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_limit($where,10,$start_page);
		$data['node_list'] = $this->m_config->get_node($limitid);
		//print_R($data['list']);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/limit',$data);
	}

	public function limit_add($limitid='')
	{
		$this->load->model('m_config');
		$parentid = $this->input->get('parentid');
		if($parentid){
			$data['node_list'] = $this->m_config->get_node($parentid);
		}
		if($limitid){
			$data['info'] = $this->m_public->getRowInfo('limit',array('limitid'=>$limitid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/limit_add',$data);
	}

	public function limit_action($limitid='')
	{
		$info = $this->input->post();
		if($limitid){
			$this->m_public->editInfo(array('limitid'=>$limitid),$info,'limit');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('limit',$info);
			}
		}
		redirect('config/limit');
	}

	public function move($id='')
	{
		$this->load->model('m_config');
		$this->load->library('tree');
		$cl_data['column'] = 'modulename,sysmoduleid,parentid';
		if($id){
			$cl_data['where'] = "parentid` != '$id' AND `sysmoduleid` != '$id'";
			$v_data['limit'] = $this->m_public->getRowInfo('sysmodule',array('sysmoduleid'=>$id),'modulename,sysmoduleid');
		}
		$limitArr = $this->m_config->get_limit_mv($cl_data);
		$this->tree->setTree($limitArr, 'sysmoduleid', 'parentid', 'modulename');
        $tree = $this->tree->getOptions(0, 0, 0, '|——');
        $v_data['tree'] = $tree;
        $this->load->view('config/move', $v_data);
	}

	public function move_action($id)
	{
		$data = $this->input->post();
		$this->m_public->editInfo(array('sysmoduleid'=>$id),$data,'sysmodule');
		redirect('config/sysmodule');
	}

	public function sysrole(){
		$this->load->model('m_config');
		$where = "sysroleid` != \"\"";
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1') || ($key == 'sysrolegroupid' && $value == '-1')){
						unset($search[$key]);
						continue;
					}
					if($key == 'rolename'){
						//$this->db->like('title', 'match', 'both');
						$where .= " AND `t_sysrole`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ||  $key == 'sysrolegroupid' ){
						$where .= " AND `t_sysrole`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('sysrole',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_sysrole($where,10,$start_page);
		$data['node_list'] = $this->m_config->get_node($limitid);
		//print_R($data['list']);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/sysrole',$data);
	}

	public function sysrole_add($sysroleid='')
	{
		$this->load->model('m_config');
		$data['group'] = $this->m_public->getAllInfo('sysrolegroup',array(),'sysrolegroupid,rolegroupname');
		if($sysroleid){
			$data['info'] = $this->m_public->getRowInfo('sysrole',array('sysroleid'=>$sysroleid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/sysrole_add',$data);
	}

	public function sysrole_action($sysroleid='')
	{
		$info = $this->input->post();
		if($sysroleid){
			$this->m_public->editInfo(array('sysroleid'=>$sysroleid),$info,'sysrole');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('limit',$info);
			}
		}
		redirect('config/sysrole');
	}

	public function sysrole_limit($sysroleid='')
	{
		$this->load->helper('array_func_helper');
		$moduleArr = $this->m_public->getAllInfo('sysmodule',array('isclose'=>0),'sysmoduleid,modulename,parentid,syslimitids,modulevalue');
		if(!empty($moduleArr)){
			$data['list'] = _findChildren($moduleArr,0);
			$data['syslimit'] = $this->m_public->getAllInfo('syslimit',array('isclose'=>0),'syslimitid,limitname,limitvalue');
			$data['sysrolelimit'] = $this->m_public->getAllInfo('sysrolelimit',array('sysroleid'=>$sysroleid));
			$modulArr = $this->m_public->getRowInfo('sysrole',array('sysroleid'=>$sysroleid,'isclose'=>0),'sysmoduleids');
			if(!empty($modulArr)){
				$data['modelids'] = explode(',', $modulArr['sysmoduleids']);
			}
			//print_r($data['modelids']);
		}
		$data['sysroleid'] = $sysroleid;
		$this->load->view('config/sysrole_limit',$data);
	}

	public function sysrole_limit_action($sysroleid='')
	{
		$data = $this->input->post();
		if($data['sysmoduleid']){
			$str = '-1,';
			foreach ($data['sysmoduleid'] as $key => $value) {
				$str .= $value.',';
			}
			$str .= '-1';
		}
		$newArr = array();
		if($data['limitvalue']){
			foreach ($data['limitvalue'] as $key => $value) {
				$member = explode(':',$value);
				$newArr[$key]['sysroleid'] = $sysroleid;
				$newArr[$key]['modulevalue'] = $member[0];
				$newArr[$key]['limitvalue'] = $member[1];
			}
		}
		$this->m_public->editInfo(array('sysroleid'=>$sysroleid),array('sysmoduleids'=>$str),'sysrole');
		$this->m_public->delInfo('sysrolelimit',array('sysroleid'=>$sysroleid));
		$this->m_public->addAllInfo('sysrolelimit',$newArr);
		redirect('config/sysrole');
	}

	public function sysrolegroup(){
		$this->load->model('m_config');
		$where = "sysrolegroupid` != \"\"";
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1') ){
						unset($search[$key]);
						continue;
					}
					if($key == 'rolegroupname'){
						$where .= " AND `t_sysrolegroup`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `t_sysrolegroup`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('sysrolegroup',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_sysrolegroup($where,10,$start_page);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/sysrolegroup',$data);
	}

	public function sysrolegroup_add($sysrolegroupid='')
	{
		$this->load->model('m_config');
		if($sysrolegroupid){
			$data['info'] = $this->m_public->getRowInfo('sysrolegroup',array('sysrolegroupid'=>$sysrolegroupid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/sysrolegroup_add',$data);
	}

	public function sysrolegroup_action($sysrolegroupid='')
	{
		$info = $this->input->post();
		if($sysrolegroupid){
			$this->m_public->editInfo(array('sysrolegroupid'=>$sysrolegroupid),$info,'sysrolegroup');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('sysrolegroup',$info);
			}
		}
		redirect('config/sysrolegroup');
	}

    public function area(){
        $this->load->model('m_config');
        $where = "area.areaid` != \"\" and `parentid`=0";
        $search = $this->input->post();
        if(!empty($search)){
            foreach ($search as $key => $value) {
                if($value == ''){
                    unset($search[$key]);
                    continue;
                }else{
                    if(($key == 'isclose' && $value == '-1') ){
                        unset($search[$key]);
                        continue;
                    }
                    if($key == 'limitname' || $key == 'limitvalue'){
                        $where .= " AND  `t_syslimit`.`$key` LIKE '%$value%'";
                    }elseif($key == 'isclose' ){
                        $where .= " AND `t_syslimit`.`$key` = '$value'";
                    }
                }
            }
        }
        $data['list'] = $this->m_config->get_area($where);
        foreach($data['list'] as $key => $val){
            if($val['parentid'] != 0){
                $where = "`areaid !='' and `areaid`=".$val['parentid'];
                $parentInfo = $this->m_public->getRowInfo('area',$where,'areaname');
                $data['list'][$key]['parentname'] = $parentInfo['areaname'];
            }else{
                $data['list'][$key]['parentname'] = '根地区';
            }
        }
        $this->load->view('config/area',$data);
    }

    public function area_add($areaid){
        $this->load->model('m_config');
        if($areaid){
            $data['info'] = $this->m_public->getRowInfo('area',array('areaid'=>$areaid));
        }else{
            $data['info'] = '';
        }
        $this->load->view('config/area_add',$data);
    }

    public function area_action($areaid='')
    {
        $info = $this->input->post();
        if($areaid){
            $this->m_public->editInfo(array('areaid'=>$areaid),$info,'area');
        }else{
            if(!empty($info)){
                $info['adminid'] = $this->session->userdata['user_id'];
                $info['addtime'] = date('Y-m-d H:i:s');
                $this->m_public->addRowInfo('area',$info);
            }
        }
        redirect('config/area');
    }

    public function area_child_action($areaid='')
    {
        $info = $this->input->post();
        if(!empty($info)){
            $info['adminid'] = $this->session->userdata['user_id'];
            $info['addtime'] = date('Y-m-d H:i:s');
            if($info['parentid'] != 0){
                $where = "`areaid !='' and `areaid`=".$info['parentid'];
                $parentInfo = $this->m_public->getRowInfo('area',$where,'childnum');
                $parentInfo['childnum'] += 1;
                $this->m_public->editInfo(array('areaid'=>$info['parentid']),$parentInfo,'area');
            }
            $this->m_public->addRowInfo('area',$info);
        }
        redirect('config/area');
    }

    public function area_child_add($areaid){
        $this->load->model('m_config');
        if($areaid){
            $data['info'] = $this->m_public->getRowInfo('area',array('areaid'=>$areaid));
        }else{
            $data['info'] = '';
        }
        $this->load->view('config/area_child_add',$data);
    }

    public function ajaxArea($id){
        $this->load->model('m_config');
        $where['parentid'] = $id;
        $areas = $this->m_config->get_area($where);
        foreach($areas as $key => $val){
            $where = "`areaid !='' and `areaid`=".$val['parentid'];
            $parentInfo = $this->m_public->getRowInfo('area',$where,'areaname');
            $areas[$key]['parentname'] = $parentInfo['areaname'];
        }
        echo json_encode($areas);
    }



    public function ajax_implore($id){
        $total_info = $this->m_public->getAllInfo('area',array(),'areaid,parentid');
        $parent_arr = array($id);
        $target_arr = array();
        foreach($total_info as $key=>$val){
            if(in_array($val['parentid'],$parent_arr)){
                $target_arr[] = $val['areaid'];
                $parent_arr[] = $val['areaid'];
            }
        }
        echo json_encode($target_arr);
    }

	public function syslimit(){
		$this->load->model('m_config');
		$where = "syslimit.syslimitid` != \"\"";
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1') ){
						unset($search[$key]);
						continue;
					}
					if($key == 'limitname' || $key == 'limitvalue'){
						$where .= " AND  `t_syslimit`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `t_syslimit`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('syslimit',$where,'count(*) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_syslimit($where,10,$start_page);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/syslimit',$data);
	}

	public function syslimit_add($syslimitid='')
	{
		$this->load->model('m_config');
		if($syslimitid){
			$data['info'] = $this->m_public->getRowInfo('syslimit',array('syslimitid'=>$syslimitid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/syslimit_add',$data);
	}

	public function syslimit_action($syslimitid='')
	{
		$info = $this->input->post();
		if($syslimitid){
			$this->m_public->editInfo(array('syslimitid'=>$syslimitid),$info,'syslimit');
		}else{
			if(!empty($info)){
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('syslimit',$info);
			}
		}
		redirect('config/syslimit');
	}

	//
	public function sysmodule(){
		$this->load->model('m_config');
		$sysmoduleid = $this->input->get('parentid');
		if($sysmoduleid){
			$where = "parentid = '$sysmoduleid'";
			$data['sysmoduleid'] = $sysmoduleid;
		}else{
			$where = "parentid` = '0' ";
			$data['sysmoduleid'] = 0;
		}
		$search = $this->input->post();
		if(!empty($search)){
			foreach ($search as $key => $value) {
				if($value == ''){
					unset($search[$key]);
					continue;
				}else{
					if(($key == 'isclose' && $value == '-1')){
						unset($search[$key]);
						continue;
					}
					if($key == 'modulename' || $key == 'modulevalue'){
						$where .= " AND `t_sysmodule`.`$key` LIKE '%$value%'";
					}elseif($key == 'isclose' ){
						$where .= " AND `t_sysmodule`.`$key` = '$value'";
					}
				}
			}
		}
		$page = isset($_GET['page'])?$_GET['page']:1;//当前页
		$cntArr = $this->m_public->getRowInfo('sysmodule',$where,'count(1) as cnt');
		$arr = array (
			'page' => $page,//当前页
		    'page_size' => 10,     //分页总大小
		    'total' => $cntArr['cnt']//总记录数
		);
		$start_page = ($page-1)*10;
		$data['list'] = $this->m_config->get_sysmodule($where,10,$start_page);
		$data['node_list'] = $this->m_config->get_module_node($sysmoduleid);
		$data['pagination'] = new pagination($arr);
		$this->load->view('config/sysmodule',$data);
	}

	public function sysmodule_add($sysmoduleid='')
	{
		$this->load->helper('array_func_helper');
		$this->load->model('m_config');
		$parentid = $this->input->get('parentid');
		if($parentid){
			$data['node_list'] = $this->m_config->get_module_node($parentid);
		}
		$data['syslimit'] = $this->m_public->getAllInfo('syslimit',array('isclose'=>0),'syslimitid,limitname');
		if($sysmoduleid){
			$data['info'] = $this->m_public->getRowInfo('sysmodule',array('sysmoduleid'=>$sysmoduleid));
		}else{
			$data['info'] = '';
		}
		$this->load->view('config/sysmodule_add',$data);
	}

	public function sysmodule_action($sysmoduleid='')
	{
		$info = $this->input->post();
		if(!empty($info['syslimitid'])){
			$str = '-1,';
			foreach($info['syslimitid'] as $v){
				$str .= $v.",";
			}
			$str.= '-1';
			unset($info['syslimitid']);
			$info['syslimitids'] = $str;
		}
		if($sysmoduleid){
			$this->m_public->editInfo(array('sysmoduleid'=>$sysmoduleid),$info,'sysmodule');
		}else{
			if(!empty($info)){
                if($info['parentid']!=0){
                    $parentInfo = $this->m_public->getRowInfo('sysmodule',array('sysmoduleid'=>$info['parentid']),'childnum');
                    $parentInfo['childnum'] += 1;
                    $this->m_public->editInfo(array('sysmoduleid'=>$info['parentid']),$parentInfo,'sysmodule');
                }
				$info['adminid'] = $this->session->userdata['user_id'];
				$info['addtime'] = date('Y-m-d H:i:s');
				$this->m_public->addRowInfo('sysmodule',$info);
			}
		}
		redirect('config/sysmodule');
	}
}
